<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button type="button" onclick=" grant()">点击获取水果</button>
    <p id="fruit">会是什么水果呢？</p>
    <script>
        /*3、模拟随机发放水果功能，水果品种固定，每次之发放一种并输出您获得的水果是XX
var fruits = ["苹果" ,"香蕉","梨子","西瓜","火龙果","芒果","荔枝"];
*/
        function grant() {
            var fruits = ["苹果" ,"香蕉","梨子","西瓜","火龙果","芒果","荔枝"];
            var index = Math.floor(Math.random() * 7);
            var fruit = document.getElementById("fruit");
            fruit.innerHTML = fruits[index];
        }
    </script>
</body>
</html>